package com.ctg.itrdc.imageconsole.data.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.ctg.itrdc.imageconsole.data.dao.IDockerMicroVersionDao;
import com.ctg.itrdc.imageconsole.data.entity.DockerMicroVersion;
import com.ctg.itrdc.paspsdk.data.dao.impl.BaseDaoImpl;

@Component("dockerMicroVersionDao")
public class DockerMicroVersionDaoImpl extends BaseDaoImpl implements IDockerMicroVersionDao{

	@Override
	public DockerMicroVersion selectById(Long id) {
		DockerMicroVersion version = new DockerMicroVersion();
		version.setId(id);
		return super.selectByPrimaryKey(version);
	}

	@Override
	public void deleteById(Long id) {
		DockerMicroVersion version = new DockerMicroVersion();
		version.setId(id);
		super.deleteByPrimaryKey(version);
	}

	@Override
	public void deleteByDockerMicroServiceId(Long serviceId) {
		String sql = "select * from docker_micro_version where docker_micro_service_id = ?";
		List<Object> params = new ArrayList<Object>();
		params.add(serviceId);
		List<DockerMicroVersion> list = super.jdbcFindList(sql, DockerMicroVersion.class, params);
		super.jdbcBatchDeleteByPrimary(list);		
	}

	@Override
	public List<DockerMicroVersion> selectByDockerMicroServiceId(Long serviceId) {
		String sql = "select * from docker_micro_version where docker_micro_service_id = ?";
		List<Object> params = new ArrayList<Object>();
		params.add(serviceId);
		return super.jdbcFindList(sql, DockerMicroVersion.class, params);	
	}

	@Override
	public List<DockerMicroVersion> selectByDockerMicroServiceIdAndState(Long serviceId, String state) {
		String sql = "select * from docker_micro_version where docker_micro_service_id = ? and state = ?";
		List<Object> params = new ArrayList<Object>();
		params.add(serviceId);
		params.add(state);
		return super.jdbcFindList(sql, DockerMicroVersion.class, params);
	}

	@Override
	public void updateStateAndReleaseStateAndDesc(Long id, String state, String releaseState, String releaseDesc,
			Long lastUpdateUserId, String lastUpdateTime) {
		DockerMicroVersion version = new DockerMicroVersion();
		version.setId(id);
		version.setState(state);
		version.setReleaseState(releaseState);
		version.setReleaseDesc(releaseDesc);
		version.setLastUpdateUserId(lastUpdateUserId);
		version.setLastUpdateTime(lastUpdateTime);
		super.updateSelectiveByPrimaryKey(version);
		
	}

	@Override
	public void updateIsAutoElastic(Long id, Integer isAutoElastic) {
		DockerMicroVersion version = new DockerMicroVersion();
		version.setId(id);
		version.setIsAutoElastic(isAutoElastic);
		super.updateSelectiveByPrimaryKey(version);
		
	}

	@Override
	public Integer selectSizeByDockerMicroServiceIdAndState(Long serviceId, String state) {
		DockerMicroVersion version = new DockerMicroVersion();
		version.setDockerMicroServiceId(serviceId);
		version.setState(state);
		return super.jdbcGetSize(version);
	}

	

	
	
	
}
